package com.zx.mes.disruptor.hyl.multihignconsumer;

import com.lmax.disruptor.RingBuffer;

import java.util.UUID;

/**
 * disruptor producer
 *
 * @author huayunlong
 * @date 2018-9-13
 */
public class Producer {

    private RingBuffer<Order> ringBuffer;

    public Producer(RingBuffer<Order> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }


    public void send() {
        long sequence = this.ringBuffer.next();
        try {
            Order order = this.ringBuffer.get(sequence);
            order.setId(UUID.randomUUID().toString());
        } finally {
            this.ringBuffer.publish(sequence);
        }

    }
}
